﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.Flexibles.CApCableParametersPointCloudUserControlViewModel
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.Collections.Generic;
using System.ComponentModel;


namespace DnProcessSimulateCommands.Flexibles;

public class CApCableParametersPointCloudUserControlViewModel : INotifyPropertyChanged, IDisposable
{
  private readonly CApFLEXCableNewAttributeViewModel m_attributeViewModel;
  private const string PropertyName_IsLengthNumericControlEnabled = "IsLengthNumericControlEnabled";
  private const string PropertyName_IsRadiusNumericControlEnabled = "IsRadiusNumericControlEnabled";
  private const string PropertyName_IsYoungsModulusNumericControlEnabled = "IsYoungsModulusNumericControlEnabled";

  public CApCableParametersPointCloudUserControlViewModel(
    CApFLEXCableNewAttributeViewModel attributeViewModel)
  {
    this.m_attributeViewModel = attributeViewModel ?? throw new ArgumentNullException(nameof (attributeViewModel));
    this.m_attributeViewModel.PropertyChanged += new PropertyChangedEventHandler(this.OnAttributeViewModelPropertyChanged);
  }

  public void Dispose()
  {
    this.m_attributeViewModel.PropertyChanged -= new PropertyChangedEventHandler(this.OnAttributeViewModelPropertyChanged);
  }

  public event PropertyChangedEventHandler PropertyChanged;

  public bool IsLengthNumericControlEnabled
  {
    get => this.IsCableParameterEnabled && !this.m_attributeViewModel.IsLengthOptimizationActivated;
  }

  public bool IsRadiusNumericControlEnabled
  {
    get => this.IsCableParameterEnabled && !this.m_attributeViewModel.IsRadiusOptimizationActivated;
  }

  public bool IsYoungsModulusNumericControlEnabled
  {
    get
    {
      return this.IsCableParameterEnabled && !this.m_attributeViewModel.IsYoungsModulusOptimizationActivated;
    }
  }

  private bool IsCableParameterEnabled => this.m_attributeViewModel.IsCableParameterEnabled;

  private void NotifyPropertyChanged(string propertyName)
  {
    PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
    if (propertyChanged == null)
      return;
    propertyChanged((object) this, new PropertyChangedEventArgs(propertyName));
  }

  private void NotifyPropertiesChanged(IEnumerable<string> propertyNames)
  {
    foreach (string propertyName in propertyNames)
      this.NotifyPropertyChanged(propertyName);
  }

  private void OnAttributeViewModelPropertyChanged(object sender, PropertyChangedEventArgs e)
  {
    ICollection<string> propertyNames = (ICollection<string>) new HashSet<string>();
    switch (e.PropertyName)
    {
      case "IsCableParameterEnabled":
        propertyNames.Add("IsLengthNumericControlEnabled");
        propertyNames.Add("IsRadiusNumericControlEnabled");
        propertyNames.Add("IsYoungsModulusNumericControlEnabled");
        break;
      case "IsLengthOptimizationActivated":
        propertyNames.Add("IsLengthNumericControlEnabled");
        break;
      case "IsRadiusOptimizationActivated":
        propertyNames.Add("IsRadiusNumericControlEnabled");
        break;
      case "IsYoungsModulusOptimizationActivated":
        propertyNames.Add("IsYoungsModulusNumericControlEnabled");
        break;
    }
    this.NotifyPropertiesChanged((IEnumerable<string>) propertyNames);
  }
}
